package com.markpim.concurrency.opdr3;

public class RobbenEiland {

	UnieGebouw monitor;

	public RobbenEiland() {
		monitor = new UnieGebouw();

		new Citizen().start();
		new Guard().start();
		new VIP().start();
	}

	// PERSONS ////////////////////////////////////////

	public class Citizen extends Thread {

		@Override
		public void run() {
			monitor.signIn();
			eerBetuigen();
			monitor.signOut();
			doSomething();
		}

	}

	public class VIP extends Thread {

		@Override
		public void run() {
			monitor.signIn();
			eerBetuigen();
			monitor.signOut();
			doSomething();
		}

	}

	public class Guard extends Thread {
		@Override
		public void run() {
			monitor.signIn();
			eerBetuigen();
			monitor.signOut();
			doSomething();
		}

	}

	public void doSomething() {
		try {
			Thread.sleep((long) (Math.random() * 600 + 400));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void eerBetuigen() {
		try {
			Thread.sleep((long) (Math.random() * 600 + 400));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
